<template>
	<view>
		<view v-if="isBtnMore" class="flexbox">
			<u-button class="ml5 mr5" v-for="(item, index) in nowBtnList" :key="index" :color="getColor(item.BtnColor)"
				@click="popupOpen(item)">{{ item.BtnNameShow }}</u-button>

			<u-button class="ml5 mr5" color="#D9534F" @click="show.sheet = true">更多</u-button>
		</view>

		<view v-else class="flexbox">
			<u-button class="ml5 mr5" v-for="(item, index) in nowBtnList" :key="index" :color="getColor(item.BtnColor)"
				@click="popupOpen(item)">{{ item.BtnNameShow }}</u-button>
		</view>

		<u-action-sheet :actions="btnActions" @select="onSelect" :show="show.sheet" cancelText="取消"
			@close="show.sheet = false"></u-action-sheet>

		<!-- 下一步处理弹窗 -->
		<van-popup v-model="show.next" position="bottom" :style="{ height: '70%' }">
			<view class="flexbox flexColumn  h100p">
				<view class="">
					<view class="pop-title flexCenter">{{ popTitle.def[0] }}</view>

					<view v-if="false" style="padding: 10px 16px; float: right;">
						<van-radio-group v-model="RecordValue" direction="horizontal">
							<van-radio name="Pass">{{ formData.Step_StayPassName }}</van-radio>
							<van-radio name="Reject">{{ formData.Step_StayRejectName }}</van-radio>
						</van-radio-group>
					</view>

					<van-cell :title="popTitle.def[1] + showNextName" is-link :value="nextStepName"
						@click="show.nextStep = true"></van-cell>

					<van-cell :title="popTitle.def[2]" is-link :value="listNextNow.joinUser"
						@click="show.nextHandler = true"></van-cell>
				</view>

				<view class="flexItem" :style="{ 'overflow-y': 'scroll' }">
					<van-cell v-if="formData.Step_IsStar" title="评价送审者">
						<template #right-icon>
							<van-rate v-model="score" color="#ffd21e"></van-rate>
						</template>
					</van-cell>

					<van-field v-if="formData.Step_IsAppointTime" readonly clickable name="datetimePicker"
						:value="datePicker" label="审查日期" placeholder="" @click="show.showPicker = true"
						input-align="right" />

					<van-cell v-if="formData.dtReader && formData.dtReader.length > 0" title="阅办人员" is-link></van-cell>

					<view class="pop_flow_opinion">处理意见</view>

					<view v-if="formData.Step_IsShowOption">
						<van-field v-model="opinion" rows="5" autosize type="textarea" placeholder="请输入意见"></van-field>
					</view>
				</view>

				<view class="pop_btn">
					<van-button color="#467DB9" @click="Flow_SubmitCheck">确定</van-button>
					<van-button color="#F0AD4E" @click="show.next = false">关闭</van-button>
				</view>
			</view>
		</van-popup>

		<!-- 选择人员弹窗 -->
		<van-popup v-model="show.nextHandler" position="bottom" :style="{ height: '70%' }">
			<view class="flexbox flexColumn h100p">
				<view>
					<view class="pop-title flexCenter">选择人员</view>

					<view class="pl10 pr10 pt5 pb5">
						<u-search v-model="searchValue" :show-action="true" actionText="搜索" placeholder="请输入姓名、工号、单位"
							shape="square" :animation="true" @search="btnSearch" @custom="btnSearch"
							@clear="clearSearch"></u-search>

						<!-- 						<van-search v-model="userValue" show-action placeholder="请输入名称" @clear="clearSearch"
							@search="btnSearch">
							<template #action>
								<div @click="btnSearch">搜索</div>
							</template>
						</van-search> -->
					</view>
				</view>

				<view class="flexItem" :style="{ 'overflow-y': 'scroll' }">
					<van-checkbox-group v-model="listNextNow.checked">
						<van-cell-group>
							<van-cell v-for="(item, index) in listNextNow.dtUser" clickable :key="index"
								:title="item.TrueName + '-' + item.OrgName" @click="toggle(index)">
								<template #right-icon>
									<van-checkbox :name="JSON.stringify(item)" :disabled="Step_IsHandlerRemove"
										ref="checkboxes" shape="square"></van-checkbox>
								</template>
							</van-cell>
						</van-cell-group>
					</van-checkbox-group>
				</view>

				<view class="pop_btn">
					<van-button color="#467DB9" @click="selUserOK()">确定</van-button>
					<van-button color="#F0AD4E" @click="show.nextHandler = false">关闭</van-button>
				</view>
			</view>
		</van-popup>

		<!-- 选择下一环节弹窗 -->
		<van-popup v-model="show.nextStep" position="bottom" :style="{ height: '70%' }">
			<view class="flexbox flexColumn" :style="{ height: '100%' }">
				<view class="pop-title flexCenter">选择环节</view>

				<view class="flexItem" :style="{ 'overflow-y': 'scroll' }">
					<van-radio-group v-model="nextStepName">
						<van-cell-group>
							<van-cell v-for="(item, index) in listNext" clickable :key="index" :title="item.Step_Name"
								@click="changStep(item)">
								<template #right-icon>
									<van-radio :name="item.Step_Name"></van-radio>
								</template>
							</van-cell>
						</van-cell-group>
					</van-radio-group>
				</view>

				<view class="pop_btn">
					<van-button color="#467DB9" @click="show.nextStep = false">确定</van-button>
					<van-button color="#F0AD4E" @click="show.nextStep = false">关闭</van-button>
				</view>
			</view>
		</van-popup>

		<!-- 办结弹窗 -->
		<van-popup v-model="show.over" position="bottom" :style="{ height: '70%' }">
			<view class="flexbox flexColumn" :style="{ height: '100%' }">
				<view class="pop-title flexCenter">办结</view>

				<view class="flexItem" :style="{ 'overflow-y': 'scroll' }">
					<van-cell v-if="formData.Step_IsStar" title="评价送审者">
						<template #right-icon>
							<van-rate v-model="score" color="#ffd21e"></van-rate>
						</template>
					</van-cell>

					<van-field v-if="formData.Step_IsAppointTime" readonly clickable name="datetimePicker"
						:value="datePicker" label="审查日期" placeholder="" @click="show.showPicker = true"
						input-align="right" />

					<van-cell v-if="formData.dtReader && formData.dtReader.length > 0" title="阅办人员" is-link
						:value="reader.join" @click="show.reader = true"></van-cell>

					<view class="pop_flow_opinion">处理意见</view>

					<view v-if="formData.Step_IsShowOption">
						<van-field v-model="opinion" rows="5" autosize type="textarea" placeholder="请输入意见"></van-field>
					</view>
				</view>

				<view class="pop_btn">
					<van-button color="#467DB9" @click="Flow_SubmitCheck">确定</van-button>
					<van-button color="#F0AD4E" @click="show.over = false">关闭</van-button>
				</view>
			</view>
		</van-popup>

		<!-- 终止弹窗 -->
		<van-popup v-model="show.stop" position="bottom" :style="{ height: '70%' }">
			<view class="pop-title flexCenter">终止申报</view>

			<van-cell title="" v-if="formData.Step_IsAutoSign">
				<template #right-icon>
					<van-button type="primary" size="mini" v-show="showAutoSign" @click="showAutoSign = false">文本签名
					</van-button>
					<van-button type="primary" size="mini" v-show="!showAutoSign" @click="showAutoSign = true">手写签名
					</van-button>
					<van-button type="primary" size="mini" v-show="showAutoSign">清除签名</van-button>
					<van-button type="primary" size="mini" v-show="showAutoSign">自动签名</van-button>
				</template>
			</van-cell>

			<view class="pop_flow_opinion">处理意见</view>

			<view v-if="formData.Step_IsShowOption">
				<van-field v-model="opinion" rows="5" autosize type="textarea" placeholder="请输入意见"></van-field>
			</view>

			<view class="pop_btn">
				<van-button color="#467DB9" @click="Flow_SubmitCheck">确认终止申报</van-button>
				<van-button color="#F0AD4E" @click="show.stop = false">关闭</van-button>
			</view>
		</van-popup>

		<!-- 转其他人处理弹窗 -->
		<van-popup v-model="show.change" position="bottom" :style="{ height: '70%' }">
			<view class="pop-title flexCenter">{{ popTitle.def[0] }} {{ showNextName }}</view>

			<!-- <van-cell :title="popTitle.def[1]" :value="nextStepName" @click="show.nextStep = true"></van-cell> -->

			<van-cell title="处理人" is-link :value="listNextNow.joinUser" @click="show.nextHandler = true"></van-cell>

			<van-cell v-if="formData.Step_IsStar" title="评价送审者">
				<template #right-icon>
					<van-rate v-model="score" color="#ffd21e"></van-rate>
				</template>
			</van-cell>

			<van-field v-if="formData.Step_IsAppointTime" readonly clickable name="datetimePicker" :value="datePicker"
				label="审查日期" placeholder="" @click="show.showPicker = true" input-align="right" />

			<van-cell v-if="formData.dtReader && formData.dtReader.length > 0" title="阅办人员" is-link></van-cell>

			<view class="pop_flow_opinion">处理意见</view>

			<view v-if="formData.Step_IsShowOption">
				<van-field v-model="opinion" rows="5" autosize type="textarea" placeholder="请输入意见"></van-field>
			</view>

			<view class="pop_btn">
				<van-button color="#467DB9" @click="Flow_SubmitCheck">确定</van-button>
				<van-button color="#F0AD4E" @click="show.change = false">关闭</van-button>
			</view>
		</van-popup>

		<!-- 时间弹窗 -->
		<van-popup v-model="show.showPicker" position="bottom">
			<van-datetime-picker type="date" title="选择时间" v-model="currentDate" @confirm="onConfirm"
				@cancel="showPicker = false"></van-datetime-picker>
		</van-popup>
	</view>
</template>

<script>
	export default {
		// @loading      流程按钮加载之后
		// @beforePopup  弹窗弹出前
		// @beforeSubmit 确认提交前
		// @afterSubmit  确认提交后
		// @afterOver    办结后
		props: {
			flowDataObj: {
				type: Object,
				default: () => {}
			}
			// flowDataObj: {
			// 	FlowCode: "flowcode", //流程编码
			// 	TableName: "tablename", //流程对应表
			// 	BDBM: "", //表单编码主键
			// 	Step_ID: "", //步骤ID
			// 	Run_ID: "", //Run_ID
			// 	Step_Handler_ID: "",
			// 	Step_BusinessCode: "",
			// 	FormData: "", //流程json数据
			// 	GUID: "", //GUID 记录主键？
			// 	Action: "edit", //流程按钮状态
			// 	AddBtns: [], //自定义按钮
			// 	Loading: false //加载状态
			// }
		},
		data() {
			return {
				show: {
					next: false,
					back: false,
					change: false,
					stop: false,
					over: false,
					nextStep: false,
					nextHandler: false,
					showPicker: false,
					reader: false,
					sheet: false,
					custom: false
				},
				popTitle: {
					def: ['', '', ''],
					next: ['提交', '下一环节', '下一步处理人'],
					back: ['退回', '退回环节', '退回人员'],
					change: ['转他人处理', '下一环节', '下一步处理人']
				},
				nowBtnList: [], //直接展示的按钮
				moreBtnList: [], //更多按钮
				btnActions: [], //更多按钮的选项
				btnList: [], //流程按钮数据
				isBtnMore: false, //是否有更多按钮
				Step_IsEdit: '', //当前页面是否可编辑
				Step_IsHandlerRemove: false, //当前选项是否不可移除
				//、、、、、、、、、、
				flowStepData: {}, //流程当前步骤数据源
				flowUserCode: '', //当前人员ID
				flowTrueName: '', //当前人员姓名
				flowGUID: '', //GUID
				sumbitType: '', //流程状态
				RecordValue: 'Pass', //会签显示状态
				showNextName: '',
				isShowBranch: false, //子流程标识
				//、、、、、、、、、、
				datePicker: this.$moment(new Date()).format('YYYY-MM-DD'),
				currentDate: new Date(),
				opinion: '', //意见
				formData: '', // 流程数据
				nextStepName: '', //当前选择的流程名称
				listNext: [], //所有下一步流程数据
				listNextNow: [], //当前选择的流程数据
				score: 5, //评分数
				showAutoSign: true, //是否显示自动签名
				checkUser: [], //选中的人员
				checkdBtn: {},
				reader: {
					list: [], //阅办人员
					listSel: [], //选中的阅办人员
					listCheck: [], //默认选择的阅办人员
					join: '' //阅办人员 、显示
				},
				objNext: {},

				protoList: [], //人员数据源
				searchValue: '', //搜索人员关键字
				homePath: '/pages/home'
			};
		},
		mounted() {
			this.$api
				.GetUserInfo({
					loading: false
				})
				.then(data => {
					this.flowUserCode = data.ryid;
					this.flowTrueName = data.ryxm;
					this.flowGUID = data.GUID;

					return this.$api.myAjaxFunc(
						Config.PlatformAPI + publicJs.Config.WorkFlowRun.GetFlowStepByStepHandlerID, {
							StepHandlerID: this.flowDataObj.Step_Handler_ID,
							RunID: this.flowDataObj.Run_ID,
							Action: this.flowDataObj.Action
						}, {
							loading: false
						}
					);
				})
				.then(data => {
					if (data.success) {
						this.flowStepData = data.resultData;
						this.Step_IsEdit = data.resultData.Step_IsEdit;
						this.Step_IsHandlerRemove = data.resultData.Step_IsHandlerRemove;

						const btnList = data.resultData.btns;
						let needBtnList = [];

						if (btnList.length != 0) {
							needBtnList = btnList.filter(item => !(item.BtnFunc == 'func_CKJD' || item.BtnFunc ==
								'func_Save' || item.BtnFunc == 'func_SaveBack'));

							if (needBtnList.length > 2) {
								this.isBtnMore = true;
								this.nowBtnList = needBtnList.slice(0, 2);
								this.moreBtnList = needBtnList.slice(2, needBtnList.length + 1);
								this.moreBtnList.forEach(item => {
									item.name = item.BtnNameShow;
								});

								this.btnActions = this.moreBtnList;
							} else {
								this.nowBtnList = needBtnList;
							}
						}

						return needBtnList;
					} else {
						this.$gl.toastFail(data.resultData);
					}
				})
				.then(res => {
					this.$emit('loading', res);
				});
		},
		methods: {
			getColor(param) {
				if (param == 'primary') {
					return '#337AB7';
				}
				if (param == 'warning') {
					return '#FF9900';
				}
			},
			onSelect(e) {
				this.popupOpen(e);
			},
			popupOpen(param) {
				this.checkdBtn = param;

				new Promise((resolve, reject) => {
						this.$emit('beforePopup', param, resolve, reject);
					})
					.then(res => {
						this.popupOpened(param);
					})
					.catch(err => {
						this.$gl.toastWarning(err);
					});
			},
			popupOpened(param) {
				//提交下一步
				if (param.BtnFunc == 'func_Sumbit' || param.BtnFunc == 'func_SeflDefine') {
					this.sumbitType = 'Sumbit';
					this.Flow_ShowFlowNext(param.StepBtnID, param.Step_Next);
				}
				//退回
				if (param.BtnFunc == 'func_Back') {
					this.sumbitType = 'Back';
					this.Flow_ShowFlowBack(param.Step_Next);
				}
				//转他人处理
				if (param.BtnFunc == 'func_ChangeToOrther') {
					this.sumbitType = 'Change';
					this.Flow_ShowFlowChange(param.Step_Next);
				}
				//终止
				if (param.BtnFunc == 'func_Stop') {
					this.sumbitType = 'Stop';
					this.Flow_ShowFlowStop(param.Step_Next);
				}
				//办结
				if (param.BtnFunc == 'func_Over') {
					this.sumbitType = 'Over';
					this.Flow_ShowFlowOver(param.Step_Next);
				}
			},
			Flow_ShowFlowNext(StepBtnID, NextStepID) {
				//如果是首次提交
				if (this.$gl.IsNullOrEmpty(this.flowDataObj.Step_Handler_ID)) {} else {
					this.$api
						.myAjaxFunc(Config.PlatformAPI + publicJs.Config.WorkFlowRun.GetNextStepByStepHandlerID, {
							StepHandlerID: this.flowDataObj.Step_Handler_ID,
							Key: this.flowDataObj.BDBM,
							FormData: this.flowDataObj.Json,
							Record_State: this.RecordValue
						})
						.then(data => {
							if (data.success) {
								let arrList = data.resultData.listNext;

								arrList.forEach((item, index) => {
									var joinUser = [];
									var checkUser = [];
									item.dtSel.forEach(item2 => {
										if (!this.$gl.IsNullOrEmpty(item2.IsCanRemove)) {
											delete item2.IsCanRemove;
										}

										joinUser.push(item2.TrueName);
										checkUser.push(JSON.stringify(item2));
									});
									arrList[index].checked = checkUser;
									arrList[index].joinUser = joinUser.join('、');
								});
								this.formData = data.resultData;
								this.listNext = arrList.reverse();

								let Step = [];
								if (arrList.length == 1) {
									Step = arrList;
								} else {
									if (!this.$gl.IsNullOrEmpty(NextStepID)) {
										Step = arrList.filter(item => item.Step_ID == NextStepID);
									}
								}

								if (Step.length == 0) {
									return;
								}

								this.listNextNow = Step[0];
								this.nextStepName = Step[0].Step_Name;

								this.Flow_BindSetData(data.resultData, NextStepID);
								this.popTitle.def = this.popTitle.next;
								this.show.next = true;
							} else {
								this.$gl.toastFail('请在PC端修改提交该项!');
							}
						});
				}
			},
			Flow_BindSetData(data, NextStepID) {
				//判断是否子流程多环节
				if (this.$gl.IsNullOrEmpty(NextStepID)) {
					if (data.listNext.length > 1) {
						if (data.StepType == '分支') {
							this.showNextName = '(分支环节)';
						} else {
							this.showNextName = '(多环节)';
						}
					}
					for (var i = 0; i < data.listNext.length; i++) {
						if (data.listNext[i].Step_Type == 'complex mix') {
							this.showNextName = this.showNextName + '(子流程)';
							this.isShowBranch = true;
						}
					}
				}

				if (data.dtReader && data.dtReader.length > 0) {
					let arr = Array.from(data.dtReader);
					let list = [];
					let arrJoin = [];
					data.dtReader.forEach(item => {
						list.push(JSON.stringify(item));
						arrJoin.push(item.TrueName);
					});
					this.reader.join = arrJoin.join('、');
					this.reader.list = data.dtReader;
					this.reader.listCheck = list;
				}
			},
			Flow_ShowFlowBack(NextStepID) {
				//获取数据
				this.$api
					.myAjaxFunc(Config.PlatformAPI + publicJs.Config.WorkFlowRun.GetBackStepByStepHandlerID, {
						StepHandlerID: this.flowDataObj.Step_Handler_ID,
						Key: this.flowDataObj.BDBM,
						FormData: this.flowDataObj.Json
					})
					.then(data => {
						if (data.success) {
							//进行数据绑定
							let arrList = data.resultData.listNext;

							arrList.forEach(function(item, index) {
								var joinUser = [];
								var checkUser = [];
								item.dtSel = item.dtUser;
								item.dtSel.forEach(function(item2) {
									joinUser.push(item2.TrueName);
									checkUser.push(JSON.stringify(item2));
								});
								arrList[index].checked = checkUser;
								arrList[index].joinUser = joinUser.join('、');
							});

							this.formData = data.resultData;
							this.listNext = arrList.reverse();
							let Step = arrList.filter(item => item.Step_ID == NextStepID);

							if (Step.length == 0) {
								return;
							}

							this.listNextNow = Step[0];
							this.nextStepName = Step[0].Step_Name;

							this.Flow_BindSetData(data.resultData, NextStepID);
							this.popTitle.def = this.popTitle.back;
							this.show.next = true;
						} else {
							this.$gl.toastFail(data.resultData);
						}
					});
			},
			Flow_ShowFlowOver() {
				this.$api
					.myAjaxFunc(Config.PlatformAPI + publicJs.Config.WorkFlowRun.GetNextStepByStepHandlerID, {
						StepHandlerID: this.flowDataObj.Step_Handler_ID,
						Key: this.flowDataObj.BDBM,
						FormData: this.flowDataObj.Json
					})
					.then(data => {
						if (data.success) {
							this.formData = data.resultData;
							this.Flow_BindSetData(data.resultData);

							this.show.over = true;
						} else {
							this.$gl.toastFail(data.resultData);
						}
					});
			},
			Flow_ShowFlowChange(NextStepID) {
				this.$api
					.myAjaxFunc(Config.PlatformAPI + publicJs.Config.WorkFlowRun.GetCurrentUserByStepHandlerID, {
						StepHandlerID: this.flowDataObj.Step_Handler_ID,
						Key: this.flowDataObj.BDBM,
						FormData: this.flowDataObj.Json
					})
					.then(data => {
						if (data.success) {
							//进行数据绑定
							let arrList = data.resultData.listNext;
							this.formData = data.resultData;
							this.listNext = arrList.reverse();
							let Step = arrList.filter(item => item.Step_ID == NextStepID);

							if (Step.length == 0) {
								return;
							}

							this.listNextNow = Step[0];
							this.nextStepName = '转其他人处理';

							this.Flow_BindSetData(data.resultData, NextStepID);
							this.popTitle.def = this.popTitle.change;
							this.show.change = true;
						} else {
							this.$gl.toastFail(data.resultData);
						}
					});
			},
			Flow_ShowFlowStop() {
				//获取数据
				this.$api
					.myAjaxFunc(Config.PlatformAPI + publicJs.Config.WorkFlowRun.GetNextStepByStepHandlerID, {
						StepHandlerID: this.flowDataObj.Step_Handler_ID,
						Key: this.flowDataObj.BDBM,
						FormData: this.flowDataObj.Json
					})
					.then(data => {
						if (data.success) {
							this.formData = data.resultData;
							this.Flow_BindSetData(data.resultData);
							this.show.stop = true;
						} else {
							this.$gl.toastFail(data.resultData);
						}
					});
			},
			Flow_SubmitCheck(param) {
				new Promise((resolve, reject) => {
						this.$emit('beforeSubmit', this.checkdBtn, resolve, reject);
					})
					.then(res => {
						this.Flow_Submit(param);
					})
					.catch(err => {
						this.$gl.toastWarning(err);
					});
			},
			Flow_Submit() {
				let isOver = 0;

				let nextstep = [];
				nextstep[0] = this.listNextNow;

				//校验
				if (this.formData.Step_IsMustOption) {
					if (this.showAutoSign) {
						if (this.$gl.IsNullOrEmpty(this.opinion)) {
							this.$gl.toastWarning('请填写意见');
							return;
						}
					}
				}

				//确定提交
				if (this.sumbitType == 'Sumbit') {
					//需要给每个环节指定人员
					if (this.formData.StepType == '分支') {
						// for (var i = 0; i < this.listNextNow.length; i++) {
						// 	if (this.listNextNow.dtSel.length == 0) {
						// 		publicJs.Msg.Alert("【" + this.listNextNow.Step_Name + "】尚未选择处理人");
						// 		return;
						// 	}
						// }
					} else {
						if (this.listNextNow.Step_Type != 'end round mix' && !this.listNextNow.Step_IsAutoJump) {
							if (this.listNextNow.dtSel.length == 0) {
								this.$gl.toastWarning('【' + this.listNextNow.Step_Name + '】尚未选择处理人');
								return;
							}
						} else {
							if (this.listNextNow.Step_IsAutoJump) {} else {
								isOver = 1;
							}
						}
					}

					if (this.$gl.IsNullOrEmpty(this.flowDataObj.Step_Handler_ID)) {
						// 首次提交
					} else {
						let data = {
							StepHandlerID: this.flowDataObj.Step_Handler_ID,
							Key: this.flowDataObj.BDBM,
							FormData: this.flowDataObj.Json,
							TableName: this.flowDataObj.TableName,
							Opinion: this.opinion + '[来自手机版]',
							// SignatureUrl: ShowAutoClass ? imgurl : "",
							AppointTime: this.datePicker,
							Star: this.score,
							RecordID: this.flowGUID,
							NextStep: JSON.stringify(nextstep),
							Reader: JSON.stringify(this.reader.listSel),
							IsOver: isOver,
							Record_State: this.RecordValue
						};

						this.$api.myAjaxFunc(Config.PlatformAPI + publicJs.Config.WorkFlowRun.FlowSumbitNext, data).then(
							res => {
								if (res.success) {
									this.$gl.toastSuccess('提交成功').then(res => {
										new Promise((resolve, reject) => {
												this.$emit('afterSubmit', this.sumbitType, resolve,
												reject);
												this.show.next = false;
											})
											.then(res => {
												uni.reLaunch({
													url: this.homePath
												});
											})
											.catch(err => {
												this.$gl.toastWarning(err);
											});
									});
								} else {
									this.$gl.toastFail(data.resultData);
								}
							});
					}
				}

				//确定退回
				if (this.sumbitType == 'Back') {
					if (this.showAutoSign) {
						if (this.$gl.IsNullOrEmpty(this.opinion)) {
							this.$gl.toastFail('请填写意见');
							return;
						}
					} else {
						// if (imgurl == "") {
						// 	publicJs.Msg.Alert("请填写手写签名");
						// return;
						// }
					}

					if (this.listNextNow.dtSel.length == 0) {
						this.$gl.toastFail('【' + this.listNextNow.Step_Name + '】尚未选择退回人');
						return;
					}

					let data = {
						StepHandlerID: this.flowDataObj.Step_Handler_ID,
						Key: this.flowDataObj.BDBM,
						TableName: this.flowDataObj.TableName,
						FormData: this.flowDataObj.Json,
						Opinion: this.opinion + '[来自手机版]',
						// SignatureUrl: ShowAutoClass ? imgurl : "",
						AppointTime: this.datePicker,
						Star: this.score,
						RecordID: this.flowGUID,
						BackStep: JSON.stringify(nextstep)
					};

					//保存信息
					this.$api.myAjaxFunc(Config.PlatformAPI + publicJs.Config.WorkFlowRun.FlowBackToStep, data).then(
					res => {
						if (res.success) {
							this.$gl.toastSuccess('退回成功').then(res => {
								new Promise((resolve, reject) => {
										this.$emit('afterSubmit', this.sumbitType, resolve, reject);
										this.show.next = false;
									})
									.then(res => {
										uni.reLaunch({
											url: this.homePath
										});
									})
									.catch(err => {
										this.$gl.toastWarning(err);
									});
							});
						} else {
							this.$gl.toastFail(data.resultData);
						}
					});
				}

				//确定办结
				if (this.sumbitType == 'Over') {
					let data = {
						StepHandlerID: this.flowDataObj.Step_Handler_ID,
						Key: this.flowDataObj.BDBM,
						TableName: this.flowDataObj.TableName,
						FormData: this.flowDataObj.Json,
						Opinion: this.opinion + '[来自手机版]',
						// SignatureUrl: ShowAutoClass ? imgurl : "",
						AppointTime: this.datePicker,
						Star: this.score,
						RecordID: this.flowGUID,
						Reader: JSON.stringify(this.reader.listSel)
					};

					//保存信息
					this.$api.myAjaxFunc(Config.PlatformAPI + publicJs.Config.WorkFlowRun.FlowOverByStepHandlerID, data)
						.then(res => {
							if (res.success) {
								this.$gl.toastSuccess('办结成功').then(res => {
									new Promise((resolve, reject) => {
											this.$emit('afterOver', this.sumbitType, resolve, reject);
											this.show.over = false;
										})
										.then(res => {
											uni.reLaunch({
												url: this.homePath
											});
										})
										.catch(err => {
											this.$gl.toastWarning(err);
										});
								});
							} else {
								this.$gl.toastFail(data.resultData);
							}
						});
				}

				//确定转他人处理
				if (this.sumbitType == 'Change') {
					let data = {
						StepHandlerID: this.flowDataObj.Step_Handler_ID,
						Key: this.flowDataObj.BDBM,
						TableName: this.flowDataObj.TableName,
						FormData: this.flowDataObj.Json,
						Opinion: this.opinion + '[来自手机版]',
						// SignatureUrl: ShowAutoClass ? imgurl : "",
						AppointTime: this.datePicker,
						Star: this.score,
						RecordID: this.flowGUID,
						list: JSON.stringify(nextstep[0].dtSel),
						Reader: JSON.stringify(this.reader.listSel),
						IsOver: isOver
					};

					this.$api.myAjaxFunc(Config.PlatformAPI + publicJs.Config.WorkFlowRun.FlowStepAddHanderByStepHandlerID,
						data).then(res => {
						if (res.success) {
							this.$gl.toastSuccess('转他人处理成功').then(res => {
								new Promise((resolve, reject) => {
										this.$emit('afterSubmit', this.sumbitType, resolve, reject);
										this.show.change = false;
									})
									.then(res => {
										uni.reLaunch({
											url: this.homePath
										});
									})
									.catch(err => {
										this.$gl.toastWarning(err);
									});
							});
						} else {
							this.$gl.toastFail(data.resultData);
						}
					});
				}

				//确定终止
				if (this.sumbitType == 'Stop') {
					let data = {
						StepHandlerID: this.flowDataObj.Step_Handler_ID,
						Key: this.flowDataObj.BDBM,
						TableName: this.flowDataObj.TableName,
						FormData: this.flowDataObj.Json,
						Opinion: this.opinion + '[来自手机版]'
						// SignatureUrl: ShowAutoClass ? imgurl : "",
					};

					this.$api.myAjaxFunc(Config.PlatformAPI + publicJs.Config.WorkFlowRun.FlowStopByStepHandlerID, data)
						.then(res => {
							if (res.success) {
								this.$gl.toastSuccess('终止成功').then(res => {
									new Promise((resolve, reject) => {
											this.$emit('afterOver', this.sumbitType, resolve, reject);
											this.show.stop = false;
										})
										.then(res => {
											uni.reLaunch({
												url: this.homePath
											});
										})
										.catch(err => {
											this.$gl.toastWarning(err);
										});
								});
							} else {
								this.$gl.toastFail(data.resultData);
							}
						});
				}
			},
			changStep(item) {
				this.nextStepName = item.Step_Name;
				let Step = this.listNext.filter(it => it.Step_ID == item.Step_ID);
				this.listNextNow = Step[0];
			},
			toggle(index) {
				if (this.Step_IsHandlerRemove) {
					return;
				}

				this.$refs.checkboxes[index].toggle();
			},
			toggle2(index) {
				this.$refs.checkboxreader[index].toggle();
			},
			onConfirm(time) {
				this.datePicker = time.Format('yyyy-MM-dd');
				this.show.showPicker = false;
			},
			onSelect(item) {
				this.popupOpen(item);
			},
			selUserOK() {
				let listStr = this.listNextNow.checked;
				let listObj = [];
				let userName = [];
				listStr.filter(item => {
					let obj = JSON.parse(item);
					listObj.push(obj);
					userName.push(obj.TrueName);
				});
				this.listNextNow.dtSel = listObj;
				this.listNextNow.joinUser = userName.join(',');
				this.show.nextHandler = false;
			},
			selReaderOK() {
				let listStr = this.reader.listCheck;
				let listObj = [];
				let userName = [];
				listStr.filter(item => {
					let obj = JSON.parse(item);
					listObj.push(obj);
					userName.push(obj.TrueName);
				});
				this.reader.listSel = listObj;
				this.reader.join = userName.join(',');
				this.show.reader = false;
			},
			btnSearch(e) {
				this.protoList = this.$gl.deepClone(this.listNextNow.dtUser);

				let deep = this.$gl.deepClone(this.listNextNow.dtUser);

				if (this.searchValue == '') {} else {
					let list = deep.filter(item => item.TrueName.includes(this.searchValue) || item.OrgName.includes(this
						.searchValue) || item.UserCode.includes(this.searchValue));
					if (list.length) {
						this.listNextNow.dtUser = list;
					} else {
						this.listNextNow.dtUser = [];
					}
				}
			},
			clearSearch() {
				if (this.protoList.length) {
					this.listNextNow.dtUser = this.protoList;
				}
			}
		}
	};
</script>

<style scoped lang="scss">
	.pop-title {
		background-color: #386fa8;
		font-weight: 600;
		padding-left: 10px;
		width: 100%;
		color: #ffffff;
		height: 45px;
	}

	.pop_flow_opinion {
		padding: 8px 15px;
		background: #e3e3e3;
		font-size: 15px;
	}

	.pop_btn {
		background-color: #f3f4f6;
		display: flex;
		position: fixed;
		bottom: 0;
		width: 100%;
		z-index: 10;
		border: 0;

		.van-button {
			flex: 1;
			width: 100%;
			margin: 0px 5px;
		}
	}
</style>
